﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LotteryVote.Entity;
using System.Data.SqlClient;

namespace LotteryVote.Data
{
    public class GameTypeDataAccess : DataBase
    {
        public void InsertGameType(GameType gameType)
        {
            string sql = string.Format(@"INSERT INTO {0} ({1},{2}) VALUES (@{1},@{2})  SELECT IDENT_CURRENT('{0}')",
                GameType.TABLENAME, GameType.GAMENAME, GameType.DESCRIPTION);
            object id = base.ExecuteScalar(sql, new SqlParameter(GameType.GAMENAME, gameType.GameName),
                new SqlParameter(GameType.DESCRIPTION, gameType.Description));
            gameType.GameId = Convert.ToInt32(id);
        }
        public void UpdateGameType(GameType gameType)
        {
            string sql = string.Format(@"UPDATE {0} SET {1}=@{1},{2}=@{2} WHERE {3}=@{3}", GameType.TABLENAME,
                GameType.GAMENAME, GameType.DESCRIPTION, GameType.GAMEID);
            base.ExecuteNonQuery(sql, new SqlParameter(GameType.GAMENAME, gameType.GameName),
                new SqlParameter(GameType.DESCRIPTION, gameType.Description),
                new SqlParameter(GameType.GAMEID, gameType.GameId));
        }
        public void DeleteGameType(int gameTypeId)
        {
            string sql = string.Format(@"DELETE {0} WHERE {1}=@{1}", GameType.TABLENAME, GameType.GAMEID);
            base.ExecuteNonQuery(sql, new SqlParameter(GameType.GAMEID, gameTypeId));
        }

        public GameType GetGameType(int gameId)
        {
            string sql = string.Format(@"SELECT * FROM {0} WHERE {1}=@{1}", GameType.TABLENAME, GameType.GAMEID);
            return base.ExecuteEntity<GameType>(sql, new SqlParameter(GameType.GAMEID, gameId));
        }
        public IList<GameType> GetAllGameType()
        {
            string sql = string.Format(@"SELECT * FROM {0}", GameType.TABLENAME);
            return base.ExecuteList<GameType>(sql);
        }
    }
}
